<%@ page import="java.util.List" %>
<%@ page import="com.bdqn.entity.News" %>
<%@ page import="com.bdqn.util.PageSupport" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%--核心标签库--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--格式化标签库--%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getServerName() + ":" + request.getServerPort() + path + "/";
    String baseUrlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    pageContext.setAttribute("baseUrlPath", baseUrlPath);
%>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/common.css">
    <script src="<%=request.getContextPath()%>/static/js/jquery-1.9.1.min.js"></script>
    <style>
        .admin-list > tbody > tr > td {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .goPointer {
            cursor: pointer;
        }
    </style>
</head>

<body>
<jsp:useBean id="newsService"
             class="com.bdqn.service.Impl.NewsServiceImpl"
></jsp:useBean>
<%
    /*List<News> newsList = newsService.queryNewsAll();
    //把newsList集合存入页面作用域
    pageContext.setAttribute("newsList",newsList);*/
    /*
    计算当前页码
    用户发起列表请求时，如果没有指明页码，默认是第一页；
    如果传过来页码，就采用传过来的页码。
     */
    /*int curPageNo=1;
    if(request.getParameter("curPageNo")!=null && !request.getParameter("curPageNo").equals("")){
        curPageNo=Integer.parseInt(request.getParameter("curPageNo"));
    }
    PageSupport<News> pageSupport=PageSupport.getInstance(curPageNo);
    newsService.queryPageNews(pageSupport);
    //我们所需的一切分页信息都已经在pageSupport里了
    pageContext.setAttribute("page",pageSupport);*/

%>
<!--主体-->
<%--<c:out value="${userName}" default="没有找到userName"></c:out><br>
<c:set var="userName2" value="张三" scope="page"></c:set><br>
<c:remove var="userName2"></c:remove>&lt;%&ndash;删除标签&ndash;%&gt;
${userName2}<br>

<%
    News news1 = new News();
    pageContext.setAttribute("news1",news1);
%>
<c:set value="20210301" target="${news1}" property="title"></c:set><br>
<c:out value="${news1.title}"></c:out><br>
<c:if test="${2==2}"  var="s" scope="page">
    ${s}
    通过test判断，如果为true，则对变量s赋值为true。否则不做赋值。
</c:if><br>
<c:url var="url" value="https://baidu.com" scope="page"></c:url><br>
${url}<br>
<fmt:formatNumber value="2333333.99" type="currency"></fmt:formatNumber><br>--%>
<div class="main-content-right">
    <!--即时新闻-->
    <div class="main-text-box">
        <div class="main-text-box-tbg">
            <div class="main-text-box-bbg">
                <form name="searchForm" id="searchForm"
                      action="#" method="post">
                    <div>
                        新闻分类：
                        <select name="categoryId">
                            <option value="0">全部</option>
                            <option value='1'>国内</option>
                            <option value='2'>国际</option>
                            <option value='3'>娱乐</option>
                            <option value='4'>军事</option>
                            <option value='5'>财经</option>
                            <option value='6'>天气</option>
                        </select>
                        新闻标题<input type="text" name="title" id="title" value=''/>
                        <button type="submit" class="page-btn goPointer">GO</button>
                        <%--完整路径<%=request.getContextPath()%>/jsp/admin/newsDetailCreate.jsp--%>
                        <button type="button" onclick="javaScript:location='<%=request.getContextPath()%>/jsp/admin/newsDetailCreate.jsp'"
                                class="page-btn goPointer">增加
                        </button>
                        <input type="hidden" name="pageIndex" value="1"/>
                    </div>
                </form>
                <table cellpadding="1" cellspacing="1" class="admin-list">
                    <thead>
                    <tr class="admin-list-head">
                        <th>新闻标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${page.datas}" var="news" varStatus="vs">
                    <%--<c:choose>
                        <c:when test="${vs.count%2==0}">
                            <tr class="admin-list-td-h2">
                        </c:when>
                        <c:otherwise>
                            <tr>
                        </c:otherwise>
                    </c:choose>--%>
                        <c:if test="vs.count%2==0">
                            <tr class="admin-list-td-h2">
                        </c:if>
                        <c:if test="vs.count%2!=0">
                            <tr>
                        </c:if>
                    <tr>
                        <td>
                            <a href="news.do?key=showOne&id=${news.id}">${news.title}</a>
                        </td>
                        <td>${news.author}</td>
                        <td><%--${news.createDate}--%>
                            <fmt:formatDate value="${news.createDate}" pattern="yyyy-MM-dd HH:mm"></fmt:formatDate>
                        </td>
                        <td>
                            <a href="#">修改</a>
                            <a href="javaScript:if(confirm('您确认删除此条新闻吗？')){location='#'}">删除</a>
                        </td>
                    </tr>
                    </c:forEach>
                    <tr>
                        <td colspan="4">
                            共${page.total}条记录
                            &emsp;
                            ${page.curPageNo}/${page.pages}页
                            &emsp;
                            <c:if test="${page.curPageNo>1}">
                                <a href="news.do?key=list&curPageNo=1">首页</a>
                                &emsp;
                                <a href="news.do?key=list&curPageNo=${page.curPageNo-1}">上一页</a>
                                &emsp;
                            </c:if>
                            <c:forEach var="curPageNo" begin="1" end="${page.pages}" step="1">
                                <c:if test="${curPageNo==page.curPageNo}">
                                    <a href="news.do?key=list&curPageNo=${curPageNo}" style="color: red;font-weight: bold">${curPageNo}</a>
                                </c:if>
                                <c:if test="${curPageNo!=page.curPageNo}">
                                    <a href="news.do?key=list&curPageNo=${curPageNo}">${curPageNo}</a>
                                </c:if>
                                &emsp;
                            </c:forEach>
                            <c:if test="${page.curPageNo<page.pages}">
                                <a href="news.do?key=list&curPageNo=${page.curPageNo+1}">下一页</a>
                                &emsp;
                                <a href="news.do?key=list&curPageNo=${page.pages}">尾页</a>
                            </c:if>
                            &emsp;
                            跳转至第
                            <input type="number" id="curPageNo" value="${page.curPageNo}" style="width: 40px">
                            <button onclick="jumpToPage()">Go</button>
                            页
                        </td>
                    </tr>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<script>
    //跳转到指定页码数据的函数
    function jumpToPage() {
        var curPageNo=$("#curPageNo").val();
        if(curPageNo<1 || curPageNo>${page.pages}){
            alert("页码输入不合法！");
            return;
        }else {
            location="news.do?key=list&curPageNo="+curPageNo;
        }
    }

</script>
</body>
</html>